# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=cjson
pkgver=1.7.17
pkgrel=0
pkgdesc="Lighweight JSON parser in C"
url="https://github.com/DaveGamble/cJSON"
arch="all"
license="MIT"
makedepends="cmake samurai"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/DaveGamble/cJSON/archive/v$pkgver.tar.gz"
builddir="$srcdir/cJSON-$pkgver"

# secfixes:
#   1.7.17-r0:
#     - CVE-2023-50472
#     - CVE-2023-50471

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_AND_STATIC_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
}

sha512sums="
4feebafa5225297fa3e6a7bf23f8d31b5c3e172f437078c5a07528522ad58ca2e9c72dd9e8611241d2b8321e9aa0a1a9af7743689d1c2001d1d9cb624aae6fa8  cjson-1.7.17.tar.gz
"
